package com.javaweb.dao.impl;

import com.javaweb.dao.TagDao;
import com.javaweb.model.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class TagDaoImpl implements TagDao {

    @Autowired
    JdbcTemplate jdbcTemplate ;

    @Override
    public int insert(Tag tag) {
        String sql = "INSERT INTO tb_tag (name, create_time, update_time)" +
                " VALUES (?,?,?)" ;

        Object[] args = new Object[]{
                tag.getName(),
                new java.sql.Date(new Date().getTime()),
                new java.sql.Date(new Date().getTime())
        };

        return jdbcTemplate.update(sql,args);
    }

    @Override
    public int insertArticleTag(Integer articleId, Integer tagId) {
        String sql = "INSERT INTO tb_article_tag (article_id, tag_id)" +
                " VALUES (?,?)" ;

        Object[] args = new Object[]{
                articleId,
                tagId
        };

        return jdbcTemplate.update(sql,args);
    }
}
